//
//  KYCityWeatherVC-UI.swift
//  ZhiYunWeather
//
//  Created by Wade on 2024/7/10.
//

import Foundation
import UIKit
import QMUIKit
extension KEClassifyListDetailVC{
    func setupSubViews(){
        let contentView = UIView()
        self.view.addSubview(contentView)
        contentView.snp.makeConstraints { make in
            make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
            make.left.right.bottom.equalTo(self.view)
        }
        
        // 背景
        let bgImage = UIImageView()
        bgImage.image = .init(named: "bg_main")
        bgImage.contentMode = .scaleAspectFill
        contentView.addSubview(bgImage)
        bgImage.snp.makeConstraints { make in
            make.edges.equalTo(contentView)
        }
        
        // 返回
        let backBtn = UIButton()
        backBtn.setImage(.init(named: "ic_back"), for: .normal)
        contentView.addSubview(backBtn)
        backBtn.snp.makeConstraints { make in
            make.width.height.equalTo(40)
            make.top.equalTo(contentView)
            make.left.equalTo(contentView).offset(10)
        }
        backBtn.addTarget(self, action: #selector(backBtnClick), for: .touchUpInside)
        
        // 语言按钮
        let lanBtn = UIButton()
        lanBtn.setImage(.init(named: "ic_lan_en1"), for: .selected)
        lanBtn.setImage(.init(named: "ic_lan_en_zh1"), for: .normal)
        contentView.addSubview(lanBtn)
        lanBtn.snp.makeConstraints { make in
            make.width.height.equalTo(30)
            make.centerY.equalTo(backBtn)
            make.right.equalTo(contentView).offset(-10)
        }
        lanBtn.addTarget(self, action: #selector(lanBtnClick(sender:)), for: .touchUpInside)
        mLanBtn = lanBtn
        
        // 练习按钮
        let trainingBtn = UIButton()
        trainingBtn.setImage(.init(named: "ic_training"), for: .normal)
        contentView.addSubview(trainingBtn)
        trainingBtn.snp.makeConstraints { make in
            make.width.height.equalTo(30)
            make.centerY.equalTo(backBtn)
            make.right.equalTo(lanBtn.snp.left).offset(-20)
        }
        trainingBtn.addTarget(self, action: #selector(trainingBtnClick), for: .touchUpInside)
        mTrainingBtn = trainingBtn
        
        
        let spring1 = SpringView()
        contentView.addSubview(spring1)
        spring1.snp.makeConstraints { make in
            make.width.height.equalTo(200)
            make.top.equalTo(backBtn.snp.bottom).offset(20)
            make.centerX.equalTo(contentView)
        }
        self.springView = spring1
        self.springView?.isHidden = true
        
        // 字母
        let aBtn = UIButton()
//        aBtn.setImage(.init(named: self.content ?? "A"), for: .normal)
//        aBtn.setTitle(self.content!+self.content!.lowercased(), for: .normal)
        aBtn.titleLabel?.font = .customFont(fontSize: 160)
        aBtn.setTitleColor(.highlightTextColor, for: .normal)
        aBtn.setTitleColor(.MainTextColor, for: .highlighted)
        spring1.addSubview(aBtn)
        aBtn.snp.makeConstraints { make in
            make.edges.equalTo(spring1)
        }
        aBtn.addTarget(self, action: #selector(aBtnClick), for: .touchUpInside)
        self.aBtn = aBtn
        
        let spring2 = SpringView()
        contentView.addSubview(spring2)
        spring2.snp.makeConstraints { make in
            make.height.equalTo(500)
            make.width.equalTo(contentView)
            make.top.equalTo(backBtn.snp.bottom).offset(20)
            make.centerX.equalTo(contentView)
        }
        self.springView2 = spring2
        self.springView2?.isHidden = false
        
        // 单词
        let wordBtn = UIButton()
        wordBtn.setImage(.init(named: currentWords?.word_iamges?.first ?? ""), for: .normal)
        wordBtn.imageView?.contentMode = .scaleAspectFit
        spring2.addSubview(wordBtn)
        wordBtn.snp.makeConstraints { make in
            make.width.height.equalTo(200)
            make.centerX.top.equalTo(spring2)
            
        }
        wordBtn.addTarget(self, action: #selector(wordsImageClick), for: .touchUpInside)
        self.wordBtn = wordBtn
        
        let wordEnBtn = UIButton()
        let wordEn = currentWords?.word_en ?? ""
        let wordZh = currentWords?.word_zh ?? ""
        let words = wordEn  + "\n " + wordZh + ""
        wordEnBtn.setTitle(words, for: .normal)
        wordEnBtn.titleLabel?.font =  .customFont(fontSize: 58)
        wordEnBtn.titleLabel?.numberOfLines = 0
        wordEnBtn.titleLabel?.textAlignment = .center
        wordEnBtn.titleLabel?.lineBreakMode = .byWordWrapping
        wordEnBtn.setTitleColor(.black, for: .normal)
        wordEnBtn.setTitleColor(.MainTextColor, for: .highlighted)
        spring2.addSubview(wordEnBtn)
        wordEnBtn.snp.makeConstraints { make in
            make.left.right.equalTo(spring2)
            make.top.equalTo(wordBtn.snp.bottom).offset(20)
            make.height.equalTo(58)
        }
        wordEnBtn.addTarget(self, action: #selector(wordsBtnClick), for: .touchUpInside)
        self.wordEnBtn = wordEnBtn
        
        let seBtn = UIButton()
        seBtn.titleLabel?.font =  .systemFont(ofSize: 28)
        seBtn.titleLabel?.numberOfLines = 0
        let sentence_en = currentWords?.word_sentences!.first?.word_sentences_en ?? "";
        let sentence_zh = currentWords?.word_sentences!.first?.word_sentences_zh ?? "";
        let sentence =  sentence_en + "\n" + sentence_zh
        seBtn.setTitle(sentence, for: .normal)
        seBtn.titleLabel?.numberOfLines = 0
        seBtn.titleLabel?.lineBreakMode = .byWordWrapping
        seBtn.setTitleColor(.black, for: .normal)
        seBtn.titleLabel?.textAlignment = .center
        seBtn.setTitleColor(.MainTextColor, for: .highlighted)
        seBtn.setBackgroundImage(.init(named: "bg_word"), for: .normal)
        spring2.addSubview(seBtn)
        seBtn.snp.makeConstraints { make in
            make.left.equalTo(spring2).offset(40)
            make.right.equalTo(spring2).offset(-40)
            make.height.equalTo(Constant.kScreenWidth * 0.66)
            make.top.equalTo(wordEnBtn.snp.bottom).offset(40)
            
        }
        seBtn.addTarget(self, action: #selector(sentensBtnClick), for: .touchUpInside)
        self.sentenceBtn = seBtn
        
        let recordBtn = UIButton()
        recordBtn.setImage(.init(named: "ic_record"), for: .normal)
        contentView.addSubview(recordBtn)
        recordBtn.snp.makeConstraints { make in
            make.width.height.equalTo(80)
            make.bottom.equalTo(contentView.snp.bottom).offset(-50)
            make.centerX.equalTo(contentView)
        }
        recordBtn.addTarget(self, action: #selector(recordBtnClick), for: .touchUpInside)
        
        
        let preViewBtn = UIButton()
        preViewBtn.setImage(.init(named: "ic_pre"), for: .normal)
        contentView.addSubview(preViewBtn)
        preViewBtn.snp.makeConstraints { make in
            make.width.equalTo(40)
            make.height.equalTo(55)
            make.centerY.equalTo(spring1)
            make.left.equalTo(contentView).offset(10)
        }
        preViewBtn.addTarget(self, action: #selector(preViewBtnClick), for: .touchUpInside)
        preViewBtn.isHidden = true
        self.preBtn = preViewBtn
        
        let nextBtn = UIButton()
        nextBtn.setImage(.init(named: "ic_next"), for: .normal)
        contentView.addSubview(nextBtn)
        nextBtn.snp.makeConstraints { make in
            make.width.equalTo(40)
            make.height.equalTo(55)
            make.centerY.equalTo(spring1)
            make.right.equalTo(contentView).offset(-10)
        }
        nextBtn.addTarget(self, action: #selector(nextBtnClick), for: .touchUpInside)
        self.nextBtn = nextBtn
    }
    
    
}
